using QxFramework.Core;
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEngine.UI;


public class BagMenu : UIBase 
{
    public Cell _cell;

    private Button closeBtn;
    private ICameraManager _iCamerManager;
    private BagManager _bagManager;
    public override void OnDisplay(object args)
    {
        base.OnDisplay(args);
        transform.localPosition = Vector3.zero;
        _iCamerManager = GameMgr.Get<ICameraManager>();
        _bagManager = GameObject.Find("BagMgr").GetComponent<BagManager>();
        closeBtn = transform.Find("CloseBtn").GetComponent<Button>();
        closeBtn.onClick.AddListener(CloseBagMenu);

        RefreshBagCell();
        RefreshWeaponCell();
        RefreshPropCell();
    }
    public void RefreshBagCell()
    {
        for(int i = 0; i < 16; i++)
        {
            _cell = transform.Find("Cells/Cell" + i.ToString()).GetComponent<Cell>();
            _cell.Item = _bagManager.Bag[i];
            _cell.RefreshSprite();
        }
    }
    public void RefreshWeaponCell()
    {
        for(int i = 0; i < 4; i++)
        {
            _cell = transform.Find("Cells/WeaponCell" + i.ToString()).GetComponent<Cell>();
            _cell.Item = _bagManager.Weapon[i];
            _cell.RefreshSprite();
        }
    }
    public void RefreshPropCell()
    {
        for (int i = 0; i < 4; i++)
        {
            _cell = transform.Find("Cells/PropCell" + i.ToString()).GetComponent<Cell>();
            _cell.Item = _bagManager.Prop[i];
            _cell.RefreshSprite();
        }
    }
    public void RemoveFromBagMenu(int idOfCell)
    {
        _cell = transform.Find("Cells/Cell" + idOfCell.ToString()).GetComponent<Cell>();
        _cell.Item = null;
        _cell.RefreshSprite();
    }
    public void CloseBagMenu()
    {
        UIManager.Instance.Close(this);
        _iCamerManager.isLocked(true);
    }
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
